    //
//  PersonViewController.m
//  AirTicket
//
//  Created by imac.bmw on 11-1-4.
//  Copyright 2011 aircococ. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"

@implementation LoginViewController

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	[super loadView];
	
	UIImage *image = [UIImage imageNamed:@"loginback.png"];
	UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
	imgView.image = image;
	[self.view addSubview:imgView];
	[imgView release];
	
	image = [UIImage imageNamed:@"person.png"];
	imgView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 30, image.size.width, image.size.height)];
	imgView.image = image;
	[self.view addSubview:imgView];
	[imgView release];
	
	UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(85, 30, 60, 30)];
	label.text = @"登录名";
	label.textColor = [UIColor whiteColor];
	label.backgroundColor = [UIColor clearColor];
	[self.view addSubview:label];
	[label release];
	
	user = [[UITextField alloc]initWithFrame:CGRectMake(50, 65, 220, 30)];
	user.borderStyle = UITextBorderStyleRoundedRect;
	user.returnKeyType = UIReturnKeyDone;
	user.delegate = self;
	[self.view addSubview:user];
	[user release];

	
	image = [UIImage imageNamed:@"key.png"];
	imgView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, image.size.width, image.size.height)];
	imgView.image = image;
	[self.view addSubview:imgView];
	[imgView release];
	
	label = [[UILabel alloc]initWithFrame:CGRectMake(85, 100, 60, 30)];
	label.text = @"密码";
	label.textColor = [UIColor whiteColor];
	[self.view addSubview:label];
	label.backgroundColor = [UIColor clearColor];
	[label release];
	
	
	key = [[UITextField alloc]initWithFrame:CGRectMake(50, 135, 220, 30)];
	key.borderStyle = UITextBorderStyleRoundedRect;
	key.returnKeyType = UIReturnKeyDone;
	key.delegate = self;
	[self.view addSubview:key];
	[key release];
	
	
	image = [UIImage imageNamed:@"login.png"];
	UIButton *login = [[UIButton alloc]initWithFrame:CGRectMake(83, 170, image.size.width, image.size.height)];
	[login setBackgroundImage:image forState:UIControlStateNormal];
	[login addTarget:self action:@selector(goLogin) forControlEvents:UIControlEventTouchUpInside];
	[self.view addSubview:login];
	[login release];
	
	image = [UIImage imageNamed:@"register.png"];
	UIButton *reg = [[UIButton alloc]initWithFrame:CGRectMake(108, 240, image.size.width, image.size.height)];
	[reg setBackgroundImage:image forState:UIControlStateNormal];
	[reg addTarget:self action:@selector(goRegister) forControlEvents:UIControlEventTouchUpInside];
	[self.view addSubview:reg];
	[reg release];
	
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {

	[textField resignFirstResponder];
	return YES;
}

-(void)goLogin {
	if (user.text != NULL || key.text != NULL) {
		[clientSocket sendLogin:user.text password:key.text];
	}
	
}

-(void)goRegister {

	RegisterViewController *reg = [[RegisterViewController alloc]init];
	[self.navigationController pushViewController:reg animated:YES];
	[reg release];
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
